using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Services;


namespace DialogComponent
{
  /// <summary>
  /// This is a game component that implements IUpdateable.
  /// </summary>
  public class DialogComponent : Microsoft.Xna.Framework.DrawableGameComponent
  {
    GameComponent caller;
    public DialogComponent(Game game, GameComponent caller)
      : base(game)
    {
      this.caller = caller;
    }

    String text;
    public override void Initialize()
    {
      text = "Paused";
      var input = (Game.Services.GetService(typeof(IInputManager)) as IInputManager);
      input.OnTap += input_OnTap;

      base.Initialize();
    }

    protected override void Dispose(bool disposing)
    {
      var input = (Game.Services.GetService(typeof(IInputManager)) as IInputManager);
      input.OnTap -= input_OnTap;
      
      base.Dispose(disposing);
    }

    void input_OnTap(Vector2 tap_position)
    {
      caller.Enabled = true;
      for (int i = 0; i < Game.Components.Count; i++)
      {
        if (Game.Components[i] == this)
        {
          Game.Components.RemoveAt(i);
          this.Dispose();
          break;
        }
      }
    }

    SpriteBatch sprite_batch;
    SpriteFont font;
    protected override void LoadContent()
    {
      sprite_batch = new SpriteBatch(GraphicsDevice);
      font = Game.Content.Load<SpriteFont>("Font");
      base.LoadContent();
    }

    public override void Draw(GameTime gameTime)
    {
      sprite_batch.Begin();
      sprite_batch.Draw(Game.Content.Load<Texture2D>("White"), new Rectangle(0, 0, 800, 600), new Color(0.5f, 0.5f, 0.5f, 0.5f));
      sprite_batch.DrawString(font, text, new Vector2(50, 50), Color.Red);
      sprite_batch.End();
      
      base.Draw(gameTime);
    }
  }
}
